package com.ht.controller;


import com.alibaba.fastjson.JSON;
import com.ht.bean.*;
import com.ht.common.Treejiebie;
import com.ht.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/stu")
public class StudentController {
    @Resource
    private StudentService StuService;

    //学生表增删改查-----------------------------------------------------------
    //去学生列表页面
    @RequestMapping("/tostulist")
    public String tostulist(){

        return "stulist";
    }

    //查询学生表
    @RequestMapping("/stulist")
    @ResponseBody
    public Map stulist(int page,int limit,Student student){
        List<Map> list= StuService.allstu((page-1)*limit, limit, student);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.countStudent(student));//分页
        map.put("data",list);
        return map;
    }

    //删除学生
    @RequestMapping("/delstu")
    @ResponseBody
    public Map delstu(Integer stuId){
        Map map=new HashMap();
        boolean bln= StuService.delstu(stuId);
        if(bln){
            map.put("msg","删除成功！");
        }else{
            map.put("msg","删除失败！");
        }
        return map;
    }

    //去添加学生页面 1
    @RequestMapping("/toaddstu")
    public String toaddstu(Model model){
        List<Studentclass> sclist=StuService.sclist();//班级表
        List<Studenthuor> shlist=StuService.shlist();
        List<Major> mlist=StuService.mlist();
        model.addAttribute("mlist",mlist);
        model.addAttribute("shlist",shlist);
        model.addAttribute("sclist",sclist);
        return "addstu";
    }

    //添加学生
    @RequestMapping("/addstu")
    @ResponseBody
    public Map addstu(Student student){
        Map map=new HashMap();
        boolean bln =StuService.insestu(student);
        if(bln){
            map.put("msg","添加成功！");
        }else {
            map.put("msg","添加失败！");
        }
        return map;
    }


    //去修改页 先查学生
    @RequestMapping("/toupdstu/{stuId}")
    public String toupdstu(@PathVariable("stuId") Integer stuId, Model model){
        Student student=StuService.updstubyid(stuId);
        List<Studentclass> sclist=StuService.sclist();//班级表
        List<Studenthuor> shlist=StuService.shlist();
        List<Major> mlist=StuService.mlist();
        model.addAttribute("mlist",mlist);
        model.addAttribute("shlist",shlist);
        model.addAttribute("sclist",sclist);
        model.addAttribute("student", JSON.toJSON(student));
        return "updstu";
    }

    //修改学生
    @RequestMapping("/updstu")
    @ResponseBody
    public Map updstu(Student student){
        boolean bln=StuService.updstu(student);
        Map map=new HashMap();
        if(bln){
            map.put("msg","修改成功！");
        }else {
            map.put("msg","修改失败！");
        }
        return map;
    }


    //-----------------------------------------------------------------------------------------


    //去班级列表
    @RequestMapping("/toclasslist")
    public String toclasslist(){

        return "classlist";
    }

    //查询班级表
    @RequestMapping("/classlist")
    @ResponseBody
    public Map classlist(Integer page,Integer limit,Studentclass studentclass){
        List<Map> list=StuService.classlist((page-1)*limit,limit,studentclass);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.countclass(studentclass));//分页
        map.put("data",list);
        return map;
    }

//   去添加班级页
    @RequestMapping("/toaddclass")
    public String toaddclass(Model model){
        List<Classtype> ctlist=StuService.ctypelist();//班级类型
        List<Studentfall> falllist=StuService.sfalllist();//届别
        List<Dept> deptlist=StuService.deptlist();//系别表
        List<Major> majorlist=StuService.majorlist();//专业表
        List<Emp> emplist = StuService.emplist();//员工表
        List<Classteacher> classteacherslist= StuService.ctlist();
        model.addAttribute("ctlist",ctlist);
        model.addAttribute("falllist",falllist);
        model.addAttribute("deptlist",deptlist);
        model.addAttribute("majorlist",majorlist);
        model.addAttribute("emplist",emplist);
        model.addAttribute("classteacherslist",classteacherslist);
        return "addclass";
    }

    //添加班级
    @RequestMapping("/addclass")
    @ResponseBody
    public Map addclass(Studentclass studentclass){
        Map map=new HashMap();
        boolean bln =StuService.classadd(studentclass);
        if(bln){
            map.put("msg","添加成功！");
        }else {
            map.put("msg","添加失败！");
        }
        return map;
    }

    //删除班级
    @RequestMapping("/delclass")
    @ResponseBody
    public Map delclass(String classId){
        Map map=new HashMap();
        boolean bln= StuService.classdel(classId);
        if(bln){
            map.put("msg","删除成功！");
        }else{
            map.put("msg","删除失败！");
        }
        return map;
    }

    //去修改班级
    @RequestMapping("/toupdclass/{classId}")
    public String toupdclass(@PathVariable("classId") String classId,Model model){
        //根据ID查班级
        Studentclass sclist=StuService.classbyid(classId);
        //查表
        List<Classtype> ctlist=StuService.ctypelist();//班级类型
        List<Studentfall> falllist=StuService.sfalllist();//届别
        List<Dept> deptlist=StuService.deptlist();//系别表
        List<Major> majorlist=StuService.majorlist();//专业表
        List<Emp> emplist = StuService.emplist();//员工表
        List<Classteacher> classteacherslist= StuService.ctlist();
        model.addAttribute("sclist",JSON.toJSON(sclist));
        model.addAttribute("ctlist",ctlist);
        model.addAttribute("falllist",falllist);
        model.addAttribute("deptlist",deptlist);
        model.addAttribute("majorlist",majorlist);
        model.addAttribute("emplist",emplist);
        model.addAttribute("classteacherslist",classteacherslist);
        return "updclass";
    }

    //修改班级
    @RequestMapping("/updclass")
    @ResponseBody
    public Map updclass(Studentclass studentclass){
        Map map=new HashMap();
        boolean bln= StuService.classupd(studentclass);
        if(bln){
            map.put("msg","修改成功！");
        }else{
            map.put("msg","修改失败！");
        }
        return map;
    }

    //去查看学生
    @RequestMapping("/tolookstu/{classId}")
    public String tolookstu(@PathVariable("classId") String classId,Model model){
        model.addAttribute("classId",classId);
        return "lookstu";
    }

    //查看学生
    @RequestMapping("/lookstu/{classId}")
    @ResponseBody
    public Map lookstu(@PathVariable("classId") String classId,Integer page,Integer limit){
        List<Map> list=StuService.yfblist(classId,(page-1)*limit,limit);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.countyfb(classId));//分页
        map.put("data",list);
        return map;
    }

    //去成绩表页
    @RequestMapping("/tostuscorelist")
    public String tostuscorelist(){

        return "stuscorelist";
    }

    //查询成绩表
    @RequestMapping("/stuscorelist")
    @ResponseBody
    public Map stuscorelist(Integer page,Integer limit,Student student,Course course){
        List<Map> list = StuService.stuscorelist((page-1)*limit,limit,student,course);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.countstuscore(student,course));//分页
        map.put("data",list);
        return map;
    }

    //去新增学生成绩页面
    @RequestMapping("/toaddstuscore")
    public String toaddstuscore(Model model){
        List<Student> stulist=StuService.stulist();
        List<Term> tlist=StuService.tlist();
        List<Course> clist=StuService.clist();
        model.addAttribute("stulist",stulist);
        model.addAttribute("tlist",tlist);
        model.addAttribute("clist",clist);
        return "addstuscore";
    }

    //新增学生成绩
    @RequestMapping("/addstuscore")
    @ResponseBody
    public Map addstuscore(Studentscore studentscore){
        Map map=new HashMap();
        boolean bln= StuService.addstuscore(studentscore);
        if(bln){
            map.put("msg","新增成功！");
        }else{
            map.put("msg","新增失败！");
        }
        return map;
    }

    //删除学生成绩
    @RequestMapping("/delstuscore")
    @ResponseBody
    public Map delstuscore(String scoreId){
        Map map=new HashMap();
        boolean bln= StuService.delstuscore(scoreId);
        if(bln){
            map.put("msg","删除成功！");
        }else{
            map.put("msg","删除失败！");
        }
        return map;
    }

    //去修改学生成绩页
    @RequestMapping("/toupdstuscore/{scoreId}")
    public String toupdstuscore(Model model,@PathVariable("scoreId") String scoreId){
        Studentscore stuscore=StuService.stuscorebyid(scoreId);
        List<Student> stulist=StuService.stulist();
        List<Term> tlist=StuService.tlist();
        List<Course> clist=StuService.clist();
        model.addAttribute("stulist",stulist);
        model.addAttribute("tlist",tlist);
        model.addAttribute("clist",clist);
        model.addAttribute("stuscore",JSON.toJSON(stuscore));
        return "updstuscore";
    }

    //修改学生成绩信息
    @RequestMapping("/updstuscore")
    @ResponseBody
    public Map updstuscore(Studentscore studentscore){
        boolean bln=StuService.updstuscore(studentscore);
        Map map=new HashMap();
        if(bln){
            map.put("msg","修改成功！");
        }else{
            map.put("msg","修改失败！");
        }
        return map;
    }

    //去答辩成绩页
    @RequestMapping("/tostureplyscore")
    public String tostureplyscore(){

        return "stureplyscorelist";
    }

    //查询答辩成绩表
    @RequestMapping("/stureplyscorelist")
    @ResponseBody
    public Map stureplyscorelist(Integer page,Integer limit,Student student,Project project){
        List<Map> stureplyscore = StuService.stureplyscore((page-1)*limit,limit,student,project);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.countstureplyscore(student,project));//分页
        map.put("data",stureplyscore);
        return map;
    }

    //去添加答辩成绩
    @RequestMapping("/toaddstureplyscore")
    public String toaddstureplyscore(Model model){
        List<Student> stulist=StuService.stulist();
        List<Project> prolist=StuService.prolist();//查询项目表
        List<Emp> emplist=StuService.emplist();
        model.addAttribute("stulist",stulist);
        model.addAttribute("prolist",prolist);
        model.addAttribute("emplist",emplist);
        return "addstureplyscore";
    }

    //添加答辩成绩
    @RequestMapping("/addstureplyscore")
    @ResponseBody
    public Map addstureplyscore(Studentreplyscore studentreplyscore){
        //总分
        studentreplyscore.setScore7(studentreplyscore.getScore1()+studentreplyscore.getScore2()+studentreplyscore.getScore3()+studentreplyscore.getScore4()+studentreplyscore.getScore5()+studentreplyscore.getScore6());
        System.out.println("总分"+studentreplyscore.getScore7()+"+++++++++++++++++++++++++++++++++++");
        boolean bln=StuService.addstureplyscore(studentreplyscore);
        Map map=new HashMap();
        if (bln){
            map.put("msg","添加成功");
        }else {
            map.put("msg","添加失败");
        }
        return map;
    }


    //删除答辩成绩
    @RequestMapping("/delstureplyscore")
    @ResponseBody
    public Map delstureplyscore(String replyId){

        boolean bln=StuService.delstureplyscore(replyId);
        Map map=new HashMap();
        if (bln){
            map.put("msg","删除成功");
        }else {
            map.put("msg","删除失败");
        }
        return map;
    }

    //去修改页
    @RequestMapping("/toupdstureplyscore/{replyId}")
    public String toupdstureplyscore(Model model,@PathVariable("replyId")String replyId){
        Studentreplyscore stureplyscore=StuService.stursbyid(replyId);
        List<Student> stulist=StuService.stulist();
        List<Project> prolist=StuService.prolist();//查询项目表
        List<Emp> emplist=StuService.emplist();
        model.addAttribute("stulist",stulist);
        model.addAttribute("prolist",prolist);
        model.addAttribute("emplist",emplist);
        model.addAttribute("stureplyscore",JSON.toJSON(stureplyscore));
        return "updstureplyscore";
    }

    //修改答辩成绩
    @RequestMapping("/updstureplyscore")
    @ResponseBody
    public Map updstureplyscore(Studentreplyscore studentreplyscore){
        studentreplyscore.setScore7(studentreplyscore.getScore1()+studentreplyscore.getScore2()+studentreplyscore.getScore3()+studentreplyscore.getScore4()+studentreplyscore.getScore5()+studentreplyscore.getScore6());
        boolean bln=StuService.updstureplyscore(studentreplyscore);
        Map map=new HashMap();
        if (bln){
            map.put("msg","修改成功");
        }else {
            map.put("msg","修改失败");
        }
        return map;
    }

    //班级分配--------------------------------------------------------
    //去班级分配页
    @RequestMapping("/tobanjifp")
    private String tobanjifp(){

        return "banjifp";
    }


    //未分班学生
    @RequestMapping("/banjifplist")
    @ResponseBody
    public Map banjifplist(Integer page,Integer limit){
        List<Enrollment>emlist=StuService.list123((page-1)*limit,limit);
        Map map=new HashMap();
        map.put("code",0);
        map.put("mgs","成功");
        map.put("count",StuService.count123());//分页
        map.put("data",emlist);
        return map;
    }



    //树状图 班级名称
    @RequestMapping("/banjifp")
    @ResponseBody
    private Map banjifp(){
        List<Studentfall> ss = StuService.falllist();
        List<Studentclass> cc = StuService.classlistt();
        List<Jiebanbiao> aa = new ArrayList<>();
        for (Studentfall i :ss){
            Jiebanbiao jiebanbiao = new Jiebanbiao();
            jiebanbiao.setId(i.getFallId());
            jiebanbiao.setRoot(0);
            jiebanbiao.setTitle(i.getLevel());
            aa.add(jiebanbiao);
        }
        for (Studentclass f :cc){
            Jiebanbiao jiebanbiao = new Jiebanbiao();
            jiebanbiao.setId(f.getClassId());
            jiebanbiao.setRoot(f.getFallId());
            jiebanbiao.setTitle(f.getClassName());
            aa.add(jiebanbiao);
        }
        Treejiebie treejiebie = new Treejiebie(aa);
        List<BanjiFenpei> shuxintus = treejiebie.buildTree();

        System.out.println("<><<<>"+shuxintus);
        Map map= new HashMap();
        map.put("data",shuxintus);
        return map;
    }

    //分班
    @RequestMapping("/classfb")
    @ResponseBody
    public Map classfb(Integer [] ids ,Integer clazz){
        Map map = new HashMap();
        if(clazz!=null && clazz!=0){
            List<Enrollment> estu = StuService.wfb(ids);
            boolean bln = StuService.classfb(estu,clazz);
            boolean bln2 =StuService.deletefb(ids);
            System.out.println(ids.toString()+"jhgjnnjkh");
            if(bln){
                map.put("msg","添加成功");
            }else {
                map.put("msg","添加失败");
            }
        }else {
            map.put("msg","请选择班级");
        }
        return map;
    }





    //-------------------------------------------------------------------
    //查询招生
    @RequestMapping("/yfblist")
    @ResponseBody
    public Map yfblist(String classId,Integer page,Integer limit){
        List<Map> yfblist=StuService.yfblist(classId,(page-1)*limit,limit);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.countyfb(classId));//分页
        map.put("data",yfblist);
        return map;
    }



    //去课程类别页 -------------课程类别管理---------------------------------------------
    @RequestMapping("/tolookctype")
    public String tolookctype(){

        return "coursetypelist";
    }

    //查询课程类别
    @RequestMapping("/lookctype")
    @ResponseBody
    public Map lookctype(Integer page,Integer limit){
        List<Coursetype> ctype=StuService.lookctype((page-1)*limit,limit);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.countctype());//分页
        map.put("data",ctype);
        return map;
    }

    //去添加课程类别
    @RequestMapping("/toaddctype")
    public String toaddctype(){

        return "addctype";
    }

    //添加
    @RequestMapping("/addctype")
    @ResponseBody
    public Map addctype(Coursetype coursetype){
        boolean bln=StuService.addctype(coursetype);
        Map map=new HashMap();
        if (bln){
            map.put("msg","添加成功");
        }else {
            map.put("msg","添加失败");
        }
        return map;
    }

    //去修改
    @RequestMapping("/toupdctype/{courseTypeId}")
    public String toupdctype(Model model,@PathVariable("courseTypeId") String courseTypeId){
        Coursetype coursetype=StuService.ctypebyid(courseTypeId);
        model.addAttribute("coursetype",JSON.toJSON(coursetype));
        return "updctype";
    }

    //修改
    @RequestMapping("/updctype")
    @ResponseBody
    public Map updctype(Coursetype coursetype) {
        boolean bln = StuService.updctype(coursetype);
        Map map = new HashMap();
        if (bln) {
            map.put("msg", "修改成功");
        } else {
            map.put("msg", "修改失败");
        }
        return map;
    }

    //删除
    @RequestMapping("/delctype")
    @ResponseBody
    public Map delctype(String courseTypeId) {
        boolean bln = StuService.delctype(courseTypeId);
        Map map = new HashMap();
        if (bln) {
            map.put("msg", "删除成功");
        } else {
            map.put("msg", "删除失败");
        }
        return map;
    }


    //课程管理----课程-----------------------12312113123123123132132---------------------
    @RequestMapping("/tolookcourse")
    public String tolookcourse(){

        return "courselist";
    }

    //查询课程类别
    @RequestMapping("/lookcourse")
    @ResponseBody
    public Map lookcourse(Integer page,Integer limit){
        List<Map> course=StuService.lookcourse((page-1)*limit,limit);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.countcourse());//分页
        map.put("data",course);
        return map;
    }

    //去添加课程类别
    @RequestMapping("/toaddcourse")
    public String toaddcourse(Model model){
        List<Coursetype> clist=StuService.coursetypelist();
        model.addAttribute("clist",clist);
        return "addcourse";
    }

    //添加
    @RequestMapping("/addcourse")
    @ResponseBody
    public Map addcourse(Course course){
        boolean bln=StuService.addcourse(course);
        Map map=new HashMap();
        if (bln){
            map.put("msg","添加成功");
        }else {
            map.put("msg","添加失败");
        }
        return map;
    }

    //去修改
    @RequestMapping("/toupdcourse/{courseId}")
    public String toupdcourse(Model model,@PathVariable("courseId") String courseId){
        Course course=StuService.coursebyid(courseId);
        List<Coursetype> clist=StuService.coursetypelist();
        model.addAttribute("clist",clist);
        model.addAttribute("course",JSON.toJSON(course));
        return "updcourse";
    }

    //修改
    @RequestMapping("/updcourse")
    @ResponseBody
    public Map updcourse(Course course) {
        boolean bln = StuService.updcourse(course);
        Map map = new HashMap();
        if (bln) {
            map.put("msg", "修改成功");
        } else {
            map.put("msg", "修改失败");
        }
        return map;
    }

    //删除
    @RequestMapping("/delcourse")
    @ResponseBody
    public Map delcourse(String courseId) {
        boolean bln = StuService.delcourse(courseId);
        Map map = new HashMap();
        if (bln) {
            map.put("msg", "删除成功");
        } else {
            map.put("msg", "删除失败");
        }
        return map;
    }


    //试讲培训---------------------------试讲培训------------------------------------------------
    @RequestMapping("/tolooktrial")
    public String tolooktrial(){

        return "triallist";
    }

    //查询
    @RequestMapping("/looktrial")
    @ResponseBody
    public Map looktrial(Integer page,Integer limit){
        List<Map> course=StuService.looktrial((page-1)*limit,limit);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.counttrial());//分页
        map.put("data",course);
        return map;
    }

    //去添加
    @RequestMapping("/toaddtrial")
    public String toaddtrial(Model model){
        List<Course> courselist=StuService.courselist();
        List<Emp> elist=StuService.elist();
        model.addAttribute("courselist",courselist);
        model.addAttribute("elist",elist);
        return "addtrial";
    }

    //添加
    @RequestMapping("/addtrial")
    @ResponseBody
    public Map addtrial(Trial trial){
        boolean bln=StuService.addtrial(trial);
        Map map=new HashMap();
        if (bln){
            map.put("msg","添加成功");
        }else {
            map.put("msg","添加失败");
        }
        return map;
    }

    //去修改
    @RequestMapping("/toupdtrial/{trialId}")
    public String toupdtrial(Model model,@PathVariable("trialId") String trialId){
        Trial trial=StuService.trialbyid(trialId);
        List<Course> courselist=StuService.courselist();
        List<Emp> elist=StuService.elist();
        model.addAttribute("courselist",courselist);
        model.addAttribute("elist",elist);
        model.addAttribute("trial",JSON.toJSON(trial));
        return "updtrial";
    }

    //修改
    @RequestMapping("/updtrial")
    @ResponseBody
    public Map updtrial(Trial trial) {
        boolean bln = StuService.updtrial(trial);
        Map map = new HashMap();
        if (bln) {
            map.put("msg", "修改成功");
        } else {
            map.put("msg", "修改失败");
        }
        return map;
    }

    //删除
    @RequestMapping("/deltrial")
    @ResponseBody
    public Map deltrial(String trialId) {
        boolean bln = StuService.deltrial(trialId);
        Map map = new HashMap();
        if (bln) {
            map.put("msg", "删除成功");
        } else {
            map.put("msg", "删除失败");
        }
        return map;
    }

    //值班----------------------------------------------

    @RequestMapping("/tolookweek")
    public String tolookweek(){

        return "weeklist";
    }

    //查询
    @RequestMapping("/lookweek")
    @ResponseBody
    public Map lookweek(Integer page,Integer limit){
        List<Map> course=StuService.weeklist((page-1)*limit,limit);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.countweek());//分页
        map.put("data",course);
        return map;
    }

    @RequestMapping("/toaddweek")
    public String toaddweek(Model model){
        List<Emp> elist=StuService.elist();
        model.addAttribute("elist",elist);
        return "addweek";
    }

    //新增
    @RequestMapping("/addweek")
    @ResponseBody
    public Map addweek(Weekarrange weekarrange){
        boolean bln = StuService.addweek(weekarrange);
        Map map = new HashMap();
        if (bln) {
            map.put("msg", "新增成功");
        } else {
            map.put("msg", "新增失败");
        }
        return map;
    }

    //删除
    @RequestMapping("/delweek")
    @ResponseBody
    public Map delweek(String weekArrangeId) {
        boolean bln = StuService.delweek(weekArrangeId);
        Map map = new HashMap();
        if (bln) {
            map.put("msg", "删除成功");
        } else {
            map.put("msg", "删除失败");
        }
        return map;
    }

    //去修改
    @RequestMapping("/toupdweek/{weekArrangeId}")
    public String toupdweek(Model model,@PathVariable("weekArrangeId") String weekArrangeId){
        List<Emp> elist=StuService.elist();
        Weekarrange week=StuService.weekbyid(weekArrangeId);
        model.addAttribute("week",JSON.toJSON(week));
        model.addAttribute("elist",elist);
        return "updweek";
    }

    //修改
    @RequestMapping("/updweek")
    @ResponseBody
    public Map updweek(Weekarrange weekarrange){
        boolean bln = StuService.updweek(weekarrange);
        Map map = new HashMap();
        if (bln) {
            map.put("msg", "修改成功");
        } else {
            map.put("msg", "修改失败");
        }
        return map;
    }

    //去查看未分宿舍的学生
    @RequestMapping("/tossfp")
    public String ossfp(Model model){
        List<Studenthuor> stuh=StuService.stuh();
        model.addAttribute("stuh",stuh);
        return "ssfplist";
    }

    // 查询宿舍
    @RequestMapping("/ssfp")
    @ResponseBody
    public Map ssfp(Integer page,Integer limit){
        List<Map> hlist=StuService.hlist((page-1)*limit,limit);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.counth());//分页
        map.put("data",hlist);
        return map;
    }

    //查询未分宿舍的学生
    @RequestMapping("/ssfpstu")
    @ResponseBody
    public Map ssfpstu(Integer page,Integer limit){
        List<Student> hlist=StuService.studentlist((page-1)*limit,limit);
        Map map=new HashMap();
        map.put("code",0);//
        map.put("mgs","成功");//消息
        map.put("count",StuService.countstu());//分页
        map.put("data",hlist);
        return map;
    }

    //分班
    @RequestMapping("/fpstuss")
    @ResponseBody
    public Map fpstuss(Integer[] ids, Integer huorId){
        Map map = new HashMap();
//        Integer[] id = new Integer[StuService.cwhuor(huorId)];
//            if(StuService.cwhuor(huorId)!=0){
            if(huorId!=null && huorId!=0) {
                //循环选择的人数最大只能和床位数一致
//                    for (int i = 0;i<StuService.cwhuor(huorId)-1;i++){
//                        if (ids[i]==null){
//                            break;
//                        }
//                        id[i] = ids[i];
//                        System.out.println(id.toString());
//                    }

                int sycw = StuService.cwhuor(huorId);
                if (ids.length > sycw) {
                    map.put("msg", "床位不足");
                } else {
                    boolean bln = StuService.fpstuss(ids, huorId);
                    boolean xgrs=StuService.upshuse(huorId,StuService.cwhuorr(huorId)+ids.length);
                    if(bln || xgrs){
                        map.put("msg","添加成功");
                    }else {
                        map.put("msg","添加失败");
                    }
//                    System.out.println(ids.toString()+"jhgjnnjkh");
                }
            }
        return map;
    }
}
